﻿using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Controllers;

namespace Zeus.Controllers
{
    using Results;
    public class ZeusController : ApiController
    {
        public ZeusController() : base()
        {

        }

        private Guid _guidRequest;
        public Guid GuidRequest {
            get {
                return _guidRequest;
            }
        }


        protected override void Initialize(HttpControllerContext controllerContext)
        {
            _guidRequest = controllerContext.Request.GetCorrelationId();
            base.Initialize(controllerContext);
        }

        public virtual ZResult ToZR(object data)
        {
            return new ZResult(new ZResultFormatter()
            {
                Code = (int)ZResultCode.SUCCESS,
                Data = data,
                GuidRequest = _guidRequest.ToString("N"),
            });
        }

        public virtual ZResult Success()
        {
            return new ZResult(new ZResultFormatter()
            {
                Code = (int)ZResultCode.SUCCESS,
                GuidRequest = _guidRequest.ToString("N"),
            });
        }

        public virtual ZResult Faild(Exception ex)
        {
            return new ZResult(new ZResultFormatter()
            {
                Code = (int)ZResultCode.FAILD,
                GuidRequest = _guidRequest.ToString("N"),
                Message = ex.Message,
            });
        }

        public virtual ZResult Faild(int code, string message)
        {
            return new ZResult(new ZResultFormatter()
            {
                Code = code,
                GuidRequest = _guidRequest.ToString("N"),
                Message = message,
            });
        }

        public virtual ZFileResult ToZFR(IZFileResultFormatter zFileResultFormatter)
        {
            return new ZFileResult(zFileResultFormatter);
        }

    }
}
